﻿using System;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using YEA.Utilities.Common;

namespace YEA.Monitor.NotificationService
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            if (args.Any<string>(val => val.Equals("/install", StringComparison.OrdinalIgnoreCase)))
            {
                UtilitiesHelper.Install(typeof(Program), true);
                return;
            }
            if (args.Any<string>(val => val.Equals("/uninstall", StringComparison.OrdinalIgnoreCase)))
            {
                UtilitiesHelper.Install(typeof(Program), false);
                return;
            }
#if DEBUG
            Controller c = new Controller();
            c.Start();
#else
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
			{ 
				new NotificationManagerService() 
			};
            ServiceBase.Run(ServicesToRun);
#endif
        }

        public static void Run(Type type)
        {
            var installArgs = new[]
            {
                type.Assembly.Location
            };
            ManagedInstallerClass.InstallHelper(installArgs);
        }
    }
}
